package model;

import model.type.AddressType;
import model.type.SubjectType;
import db.ImbiConnection;

public class Address implements Comparable<Address>{
	
	private final int id;
	private int addressType;
	private int subject;
	private int subjectType;
	private String country;
	private String county;
	private String townVillage;
	private String streetAddress;
	private String zipcode;
	
	public Address(int id, int addressType, int subject, int subjectType,
			String country, String county, String townVillage,
			String streetAddress, String zipcode) {
		super();
		this.id = id;
		this.addressType = addressType;
		this.subject = subject;
		this.subjectType = subjectType;
		this.country = country;
		this.county = county;
		this.townVillage = townVillage;
		this.streetAddress = streetAddress;
		this.zipcode = zipcode;
	}

	public int getAddressType() {
		return addressType;
	}

	public void setAddressType(int addressType) {
		this.addressType = addressType;
	}

	public int getSubject() {
		return subject;
	}

	public void setSubject(int subject) {
		this.subject = subject;
	}

	public int getSubjectType() {
		return subjectType;
	}

	public void setSubjectType(int subjectType) {
		this.subjectType = subjectType;
	}

	public String getCountry() {
		return country;
	}

	public void setCountry(String country) {
		this.country = country;
	}

	public String getCounty() {
		return county;
	}

	public void setCounty(String county) {
		this.county = county;
	}

	public String getTownVillage() {
		return townVillage;
	}

	public void setTownVillage(String townVillage) {
		this.townVillage = townVillage;
	}

	public String getStreetAddress() {
		return streetAddress;
	}

	public void setStreetAddress(String streetAddress) {
		this.streetAddress = streetAddress;
	}

	public String getZipcode() {
		return zipcode;
	}

	public void setZipcode(String zipcode) {
		this.zipcode = zipcode;
	}

	public int getId() {
		return id;
	}	
	
	@Override
	public String toString() {
		return streetAddress+", "+townVillage+", "+county+", "+country+", "+getZipcode();		
	}
	
	@Override
	public int compareTo(Address o) {
		return ((Integer)getAddressType()).compareTo(o.getAddressType());		
	}
	
	/*OBJECT ACCESS METHODS*/
	
	
	public String getSubjectTypeString(){
		return SubjectType.getSubjectType(getSubjectType()).getType();
	}
	
	public String getAddressTypeString(){
		return AddressType.getAddressType(getAddressType()).getType();
	}
	
	public Object getSubjectObject(){
		if(getSubjectType() == SubjectType.ENTERPRISE)
			return ImbiConnection.getEnterpriseDAO().find(getSubject());
		if(getSubjectType() == SubjectType.PERSON)
			return ImbiConnection.getPersonDAO().find(getSubject());
		return null;
	}

	
	
}
